from django.forms import model_to_dict
from django.shortcuts import render

# Create your views here.
from django.views import View
from .models import BookInfo
from django.http import JsonResponse,HttpResponse


class BooksView(View):

    def get(self,request):
        dict1 = {}
        content = BookInfo.objects.all()
        for content in content:
            content = model_to_dict(content)
            print(content)
            dict1[content['id']] = content



        # return HttpResponse(dict1)
        return JsonResponse(dict1)
        # return render(request,'book.html',content)

    def post(self,request):
        pass

    def put(self,request):
        pass

    def delete(self,request):
        content = BookInfo.objects.get(id='')
        content.delete()
        pass